package cn.javabb.bootdemo.base;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author QINB imqinbao@163.com
 * @CreateDate 2019/1/16/016 17:34
 * @Since V1.0
 */
public class CommonUtil  {

    public static List<List<?>> splitList(List<?> list, int len) {
        if (list == null || list.size() == 0 || len < 1) {
            return null;
        }

        List<List<?>> result = new ArrayList<List<?>>();


        int size = list.size();
        int count = (size + len - 1) / len;


        for (int i = 0; i < count; i++) {
            List<?> subList = list.subList(i * len, ((i + 1) * len > size ? size : len * (i + 1)));
            result.add(subList);
        }
        return result;

    }
}
